package com.qxbb.report.utils;


import org.apache.commons.collections4.CollectionUtils;

import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.List;

/**
 * 通用工具类
 *
 * @author Z0001
 * @since 2020-5-12
 */
public class CommonUtil {

    /**
     * 判断对象是否为空 长度是否为0
     *
     * @param obj 对象
     * @return 是否为空
     */
    public static boolean isEmpty(Object obj) {
        if (obj == null) {
            return true;
        } else {
            if (obj instanceof List) {
                return CollectionUtils.isEmpty((List) obj);
            }

            if (obj instanceof Array) {
                return CollectionUtils.isEmpty(Arrays.asList(obj));
            }

            if (obj instanceof String) {
                return StringUtils.isEmpty(String.valueOf(obj));
            }

            if (obj instanceof Long) {
                return (Long) obj == 0;
            }
        }

        return false;
    }
}
